/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author TranDua
 */
public class Util {
    public String getTen(String ten, String field, String ma, String tb) throws SQLException {
        String str = "";
        String ten_ = "select " + ten + " from " + tb + " where " + field + " ='" + ma + "'";
        PreparedStatement ps = ConSQL.getCon().prepareCall(ten_);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            str = rs.getString(ten);
        }
        return str;
    }
    public String getMa(String ten, String colName, String fieldName, String tb) throws SQLException {
//        String temp = "";
        try {
            String str = "select " + colName + " from " + tb + " where " + fieldName + " = N'" + ten + "'";
            PreparedStatement ps = ConSQL.getCon().prepareCall(str);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
//                temp = rs.getString(1);
                return rs.getString(1);
            }
        } catch (SQLException ex) {
            throw ex;
        }
        return "";
//        return temp;
    }
}
